package soccer.ui;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import soccer.domain.Klasemen;
import soccer.domain.Klub;

public class AplikasiKlasemen {
	private static Klasemen klasemen = new Klasemen();
	
	public static void main(String[] args) throws Exception {
		inisialisasi();
		System.out.println("0. (Exit)");
		System.out.println("1. Arsenal");
		System.out.println("2. Man Utd");
		System.out.println("3. Portsmouth");
		System.out.println("4. Chelsea");
		System.out.println("Choose the first Team: ");
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String team1 = bf.readLine();
		System.out.println("Choose the second Team: ");
		BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in));
		String team2 = bf1.readLine();
		
		System.out.println("Enter the match result: " + klasemen.getDatabase().get("3").getNama() + " vs " +
				klasemen.getDatabase().get(team2).getNama());
		displayKlasemen();
//		terimaInput();
	}

	private static void terimaInput() {
		// baca input ke variabel 
		Integer klub1 = 1;
		Integer klub2 = 9;
		Integer goal1 = 1;
		Integer goal2 = 0;
		
		// update klasemen dengan method input
		klasemen.inputMatch(klub1, klub2, goal1, goal2);
		
		displayKlasemen();
	}

	private static void displayKlasemen() {
		List<Klub> daftarKlub = klasemen.urutkanBerdasarkanNama();
		List<Klub> daftarKlubPoin = klasemen.urutkanBerdasarkanPoin();
		List<Klub> terakhirMain = klasemen.getTerakhirMain();
		
		System.out.println(daftarKlub);
		
		//klasemen.getDatabase().get(key)
		
//		for(int i=1 ; i<klasemen.getDatabase().size() ; i++){
//			for(Object a : klasemen.getDatabase().get(i)){
//				System.out.println(a);
//			}
//		}
			
		
		// looping dan tampilkan tabel klasemen
		// klub yang terdaftar di terakhirMain dikasi bintang
	}

	private static void inisialisasi() {
		// buat klub
		Klub manUtd = new Klub();
		manUtd.setNama("Man Utd");
		manUtd.setMatch(17);
		manUtd.setGoalsIn(38);
		manUtd.setGoalsOut(9);
		manUtd.setPoint(4);
		manUtd.setWin(14);
		manUtd.setDraw(2);
		manUtd.setLose(1);
		
		Klub arsenal = new Klub();
		arsenal.setNama("Arsenal");
		arsenal.setMatch(17);
		arsenal.setGoalsIn(27);
		arsenal.setGoalsOut(13);
		arsenal.setPoint(29);
		arsenal.setWin(8);
		arsenal.setDraw(5);
		arsenal.setLose(4);
		
		Klub chelsea = new Klub();
		chelsea.setNama("Chelsea");
		chelsea.setMatch(17);
		chelsea.setGoalsIn(27);
		chelsea.setGoalsOut(9);
		chelsea.setPoint(39);
		chelsea.setWin(12);
		chelsea.setDraw(3);
		chelsea.setLose(2);
		
		Klub port = new Klub();
		port.setNama("Portsmouth");
		port.setMatch(17);
		port.setGoalsIn(23);
		port.setGoalsOut(14);
		port.setPoint(28);
		port.setWin(8);
		port.setDraw(4);
		port.setLose(5);
		
		Map k = new HashMap();
		k.put("1", arsenal);
		k.put("2", manUtd);
		k.put("3", port);
		k.put("4", chelsea);
		
//		for(Object a : k){
//			System.out.println(a);
//			
//		}
		//System.out.println(k.get("Man Utd") +"sas");
		klasemen.setDatabase(k);
		
		// masukkan ke klasemen
	}
}
